/**
 * Created by zhangqingxi on 2017-03-31.
 */


/**
 * 加载表格
 *
 */
function  loadDataList() {

    $('#dataList').datagrid({
        url:modelPath+'findByParam.shtml',
        queryParams:{
            sort:'d.addTime',
            order:'desc'
        },
        // idField:'id',
        fitColumns:true,
        pagination:true,
        rownumbers:true,
        singleSelect:true,
        sortOrder:true,
        striped:true,
        fit:true,
        columns:[[
            {field:'id',width:10,checkbox:true},
            {field:'d.name',title:'装置名称',width:10,sortable:true,formatter:function (value,row,index) {
                return row.name;
            }},
            {field:'deptName',title:'所属部门',width:10,sortable:false},
            {field:'addUserName',title:'登记人',width:10,sortable:false},
            {field:'addDeptName',title:'登记部门',width:10,sortable:false},
            {field:'d.addTime',title:'登记时间',width:10,sortable:true,formatter:function (value,row,index) {
                return row.addTime;
            }},
            {field:'remarks',title:'备注',width:10,sortable:false}
        ]],
        view: detailview,
        detailFormatter: function(rowIndex, rowData){
            return template('deviceDetail', rowData);
        },
        onExpandRow:function (index,row) {

            var $dataList=$('#dataList');
            var rows=$dataList.datagrid('getRows');
            for(var i=0;i<rows.length;i++){
                var rowIndex=$dataList.datagrid('getRowIndex',rows[i]);
                if(index != rowIndex){
                    $dataList.datagrid('collapseRow',rowIndex);
                }
            }
        },
        onLoadSuccess:function () {
            $('.cuttle .easyui-textbox').textbox()
        },
        toolbar: '#toolbar'

    });


}



$(function () {
    loadDataList();

    //查询按钮事件
    initSearchClick();

    //重置参数
    initResetClick();
    //添加按钮事件
    $('#btn_basicInfo_device_add').on('click',function () {

        openLayer("添加装置",modelPath+"add.shtml",['600px', '380px']);

    });
    //编辑按钮事件
    $('#btn_basicInfo_device_edit').on('click',function () {

        var checkedRows=$('#dataList').datagrid('getChecked');
        if(checkedRows.length === 0){
            layer.alert("选择需要修改的行！");
            return
        }
        var id=checkedRows[0].id;

        openLayer("编辑装置",modelPath+"edit.shtml?id="+id,['600px', '380px']);


    });

    //删除按钮事件
    $('#btn_basicInfo_device_delete').on('click',function () {

        var checkedRows=$('#dataList').datagrid('getChecked');
        if(checkedRows.length === 0){
            layer.alert("选择需要删除的行！");
            return
        }

        var id=checkedRows[0].id;
        initDeleteClick(modelPath,id);

    })


});